package com.app.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.app.pojo.DevUser;

/*
 * 自定义拦截器,用于拦截未登录的非法请求
 * 	如果返回true：再调用相应的方法
 * 	如果返回false：跳转到错误页面
 */
public class SysInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		HttpSession session = request.getSession();
		DevUser devUser = (DevUser)session.getAttribute(Constants.DEVUSER_SESSION);
		if(devUser==null) {
			response.sendRedirect(request.getContextPath()+"/403.jsp");
			return false;
		}
		return true;
	}

	
}
